import api from './api';
import { MovieEpisodes, Movies, MovieSeasons } from '../types/movie';
import { PageResponse } from '../types/pageType';

// 获取所有影视数据
export const getMovies = async (pageSize: number, pageNum: number, type?: number, name?: string): Promise<PageResponse<Movies>> => {
  const response = await api.get('api/movie/listPage', {
    params: {
      pageSize,
      pageNum,
      type,
      name
    }
  });
  return response.data;
};

// 获取单个影视数据
export const getMovieById = async (id: string): Promise<Movies> => {
  const response = await api.get(`api/movie/${id}`);
  return response.data;
};
// 获取CMS采集的影视详情数据
export const getMovieCmsById = async (id: string): Promise<any> => {
  const response = await api.get(`api/movie/cms/${id}`);
  return response.data;
};

// 添加影视数据
export const createMovie = async (movie: Movies): Promise<boolean> => {
  const response = await api.post('api/movie', movie);
  return response.data;
};

// 更新影视数据
export const updateMovie = async (movie: Movies): Promise<boolean> => {
  const response = await api.put(`api/movie`, movie);
  return response.data;
};

// 删除影视数据
export const deleteMovie = async (id: string): Promise<boolean> => {
  const response = await api.delete(`api/movie/${id}`);
  return response.data;
};

// 获取影视的季数据
export const getSeasonsByMovieId = async (movieId: string): Promise<MovieSeasons[]> => {
  const response = await api.get(`api/movie/seasons/${movieId}`);
  return response.data;
};

export const createSeason = async (season: MovieSeasons): Promise<boolean> => {
  const response = await api.post('api/movie/seasons', season);
  return response.data;
};

// 更新季数据
export const updateSeason = async (season: MovieSeasons): Promise<boolean> => {
  const response = await api.put(`api/movie/seasons`, season);
  return response.data;
};

// 删除季数据
export const deleteSeason = async (id: string): Promise<boolean> => {
  const response = await api.delete(`api/movie/seasons/${id}`);
  return response.data;
};

// 获取季的剧集数据
export const getEpisodesBySeasonId = async (seasonId: string): Promise<MovieEpisodes[]> => {
  const response = await api.get(`api/movie/episodes/${seasonId}`);
  return response.data;
};

export const createEpisode = async (episode: MovieEpisodes): Promise<boolean> => {
  const response = await api.post('api/movie/episodes', episode);
  return response.data;
};

export const updateEpisode = async (episode: MovieEpisodes): Promise<boolean> => {
  const response = await api.put(`api/movie/episodes`, episode);
  return response.data;
};

export const deleteEpisode = async (id: string): Promise<boolean> => {
  const response = await api.delete(`api/movie/episodes/${id}`);
  return response.data;
};

export default api;